<template>
    <div id="app">
        <div id="cover"></div>
        <Header></Header>
        <!-- <p>{{count}}</p> -->
        <p>{{fullName}} {{counter}}</p>
        <router-link to="/app/123">app123</router-link>
        <router-link to="/app/456">app456</router-link>
        <!-- <router-link to="/app/123?d=1">app</router-link> -->
        <!-- <router-link :to="{name: 'app' }">app</router-link> -->
        <router-link to="/login">login</router-link>
        <!-- <Todo></Todo> -->

        <!-- transition 过渡特效 -->
        <transition name="fade">
            <router-view />
            <!-- <router-view></router-view> -->
        </transition>

        <Footer></Footer>
        <!-- <router-view name="a" /> -->
    </div>
</template>

<script>
import {
    mapState,
    mapGetters,
    mapActions,
    mapMutations
} from 'vuex'

import Header from './layout/header.vue'
import Footer from './layout/footer.jsx'
// 懒加载
// import Todo from './views/todo/todo.vue'

// console.log(Header.__docs)

export default {
    components: {
        Header,
        Footer,
        // Todo
    },
    mounted () {
        // console.log(this.$route.params)
        console.log(this.$store)
        // let i = 1

        // actions
        // 引入map
        // this.$store.dispatch('updateCountAsync', {
        this.updateCountAsync({
            num: 5,
            time: 2000
        })

        // setInterval ( () => {
        //     this.$store.commit('updateCount', i++)
        // }, 1000)
        // 在外面也可以修改 store.state.count
        // vue不推荐这样去做
        // this.$store.state.count = 3
        // setInterval ( () => {
        //     // this.$store.commit('updateCount', {
        //     this.updateCount({
        //         num: i++,
        //         num2: 2
        //     })
        // }, 1000)
    },
    methods: {
        ...mapActions(['updateCountAsync']),
        ...mapMutations(['updateCount'])
    },
    computed: {
        // vuex store数据
        // 一种简单的获取到store.state数据 需要上面引入
        // ...mapState (['count']), // 同名
        ...mapState ({
            // counter: 'count' // 不同名
            // 箭头函数可使代码更简练
            counter: state => state.count // 不同名
        }),
        // count () {
        //     return this.$store.state
        // },

        // mapGetters 辅助函数
        ...mapGetters(['fullName'])
        // fullName () {
        //     return this.$store.getters.fullName
        // }
    }
}
</script>

<style lang="stylus" scoped>
    #app
      position absolute
      left 0
      right 0
      top 0
      bottom 0
    #cover
        position absolute
        left 0
        right 0
        top 0
        bottom 0
        background-color #999
        opacity .1
        z-index -1
</style>
